package com.punai.costData.controller;

import cn.hutool.core.util.StrUtil;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.costData.bo.ZbStructItemChildBo;
import com.punai.costData.bo.ZbStructItemListBo;
import com.punai.costData.service.CostIndicatorService;
import com.punai.externalccb.constants.CCBConstants;
import com.punai.prodatalibrary.domain.LibProjectInfo;
import com.punai.prodatalibrary.service.ILibProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/costData/costIndicator")
public class CostIndicatorController extends BaseController {

    @Autowired
    private CostIndicatorService costIndicatorService;

    @PreAuthorize("@ss.hasPermi('costData:costIndicator:list')")
    // 获取使用的指标
    @GetMapping("/getUsedIndicator/{id}/{type}")
    public AjaxResult getUsedIndicator(@PathVariable String id, @PathVariable String type) {
        // type 转化成 stagetype
        String stagetype = CCBConstants.CCB_TYPE.getCodeByAlias(type);
        if (StrUtil.isBlank(stagetype)) {
            return AjaxResult.error("参数错误！");
        }
        List<ZbStructItemListBo> res = costIndicatorService.getUsedIndicator(id,stagetype);
        return AjaxResult.success(res);
    }

    @PreAuthorize("@ss.hasPermi('costData:costIndicator:detaillist')")
    // 获取指标详细
    @GetMapping("/getIndicatorDetail/{id}/{type}/{indicatorId}")
    public AjaxResult getIndicatorDetail(@PathVariable String id, @PathVariable String type, @PathVariable String indicatorId) {
        String stagetype = CCBConstants.CCB_TYPE.getCodeByAlias(type);
        if (StrUtil.isBlank(stagetype)) {
            return AjaxResult.error("参数错误！");
        }
        List<ZbStructItemChildBo> res = costIndicatorService.getIndicatorDetail(id,stagetype,indicatorId);
        return AjaxResult.success(res);
    }

}
